#!/bin/python
# coding=utf-8

import sys
import os

model = [(0.712355086,"SwedishFish",-31.88)
        ,(0.712355086,"MilkyWay",-31.88)
        ,(0.741204973,"PeppermintPatties",-6.63)
        ,(0.741204973,"CadburyEggs",-5.81)
        ,(0.437058824,"Twix",-1.11)
        ,(0.989637517,"CandyCorn",-0.35)
        ,(0.70609509,"CandyCorn",-0.20)
        ,(20.06333891,"Twizzlers",-0.16)
        ,(0.598936468,"PeppermintPatties",-0.11)
        ,(20.06333891,"CandyCorn",-0.04)
        ,(20.06333891,"CottonCandy",-0.04)
        ,(20.54659988,"Twizzlers",-0.04)
        ,(0.832297432,"MMs",0.00)
        ,(0.588235294,"MMs",0.00)
        ,(0.437058824,"Snickers",0.00)
        ,(0.832297432,"Snickers",0.00)
        ,(0.674523463,"Snickers",0.00)
        ,(0.631359748,"Snickers",0.00)
        ,(0.54845489,"Snickers",0.00)
        ,(0.588235294,"Snickers",0.00)
        ,(0.530867073,"Snickers",0.00)
        ,(0.437058824,"Reeses",0.00)
        ,(0.54845489,"Reeses",0.00)
        ,(0.588235294,"Reeses",0.00)
        ,(0.530867073,"Reeses",0.00)
        ,(0.588235294,"Twix",0.00)
        ,(0.989637517,"Twix",0.00)
        ,(0.437058824,"CadburyEggs",0.00)
        ,(20.49437869,"CadburyEggs",0.00)
        ,(0.54845489,"CadburyEggs",0.00)
        ,(0.588235294,"CadburyEggs",0.00)
        ,(0.437058824,"BabyRuth",0.00)
        ,(0.54845489,"BabyRuth",0.00)
        ,(0.588235294,"BabyRuth",0.00)
        ,(0.986711586,"BabyRuth",0.00)
        ,(0.54845489,"HersheyKiss",0.00)
        ,(0.588235294,"HersheyKiss",0.00)
        ,(0.530867073,"HersheyKiss",0.00)
        ,(0.437058824,"Twizzlers",0.00)
        ,(20.02687584,"Twizzlers",0.00)
        ,(20.55374424,"Twizzlers",0.00)
        ,(20.49830931,"Twizzlers",0.00)
        ,(20.34254544,"Twizzlers",0.00)
        ,(20.51611367,"Twizzlers",0.00)
        ,(20.03446014,"Twizzlers",0.00)
        ,(20.04598065,"Twizzlers",0.00)
        ,(20.04712901,"Twizzlers",0.00)
        ,(0.54845489,"Twizzlers",0.00)
        ,(0.588235294,"Twizzlers",0.00)
        ,(0.437058824,"CandyCorn",0.00)
        ,(0.789668188,"CandyCorn",0.00)
        ,(20.0824811,"CandyCorn",0.00)
        ,(20.36835772,"CandyCorn",0.00)
        ,(20.34254544,"CandyCorn",0.00)
        ,(20.03446014,"CandyCorn",0.00)
        ,(20.04598065,"CandyCorn",0.00)
        ,(20.03078729,"CandyCorn",0.00)
        ,(0.721368367,"CandyCorn",0.00)
        ,(0.674523463,"CandyCorn",0.00)
        ,(0.631359748,"CandyCorn",0.00)
        ,(0.54845489,"CandyCorn",0.00)
        ,(0.986711586,"CandyCorn",0.00)
        ,(0.437058824,"CottonCandy",0.00)
        ,(20.02687584,"CottonCandy",0.00)
        ,(20.29875331,"CottonCandy",0.00)
        ,(20.55374424,"CottonCandy",0.00)
        ,(20.54659988,"CottonCandy",0.00)
        ,(20.03446014,"CottonCandy",0.00)
        ,(20.04598065,"CottonCandy",0.00)
        ,(20.03078729,"CottonCandy",0.00)
        ,(20.04712901,"CottonCandy",0.00)
        ,(0.54845489,"CottonCandy",0.00)
        ,(0.588235294,"CottonCandy",0.00)
        ,(0.437058824,"JuniorMints",0.00)
        ,(0.631359748,"JuniorMints",0.00)
        ,(0.54845489,"JuniorMints",0.00)
        ,(0.588235294,"JuniorMints",0.00)
        ,(0.530867073,"JuniorMints",0.00)
        ,(0.54845489,"SwedishFish",0.00)
        ,(0.588235294,"SwedishFish",0.00)
        ,(0.437058824,"PeppermintPatties",0.00)
        ,(20.04712901,"PeppermintPatties",0.00)
        ,(0.631359748,"PeppermintPatties",0.00)
        ,(0.588235294,"PeppermintPatties",0.00)
        ,(0.54845489,"MilkyWay",0.00)
        ,(0.588235294,"MilkyWay",0.00)
        ,(20.04712901,"TootsieRolls",0.00)
        ,(20.0261656,"JellyBelly",0.01)
        ,(20.04712901,"CadburyEggs",0.03)
        ,(0.712355086,"BabyRuth",0.04)
        ,(20.34254544,"CottonCandy",0.04)
        ,(20.51611367,"CottonCandy",0.04)
        ,(20.03078729,"Twizzlers",0.10)
        ,(0.530867073,"BabyRuth",0.11)
        ,(20.04712901,"CandyCorn",0.13)
        ,(20.51611367,"TootsieRolls",0.14)
        ,(20.49830931,"CadburyEggs",0.19)
        ,(20.0261656,"CottonCandy",0.20)
        ,(20.03078729,"TootsieRolls",0.20)
        ,(20.04712901,"Twix",0.21)
        ,(20.0261656,"Twizzlers",0.23)
        ,(20.36835772,"Twizzlers",0.24)
        ,(20.54659988,"CandyCorn",0.24)
        ,(20.54659988,"CadburyEggs",0.25)
        ,(20.54659988,"TootsieRolls",0.25)
        ,(20.03446014,"CadburyEggs",0.27)
        ,(20.03446014,"TootsieRolls",0.27)
        ,(20.51611367,"CadburyEggs",0.28)
        ,(20.03078729,"CadburyEggs",0.29)
        ,(20.49830931,"TootsieRolls",0.31)
        ,(20.04598065,"TootsieRolls",0.31)
        ,(20.0261656,"PeppermintPatties",0.37)
        ,(0.530867073,"Twizzlers",0.37)
        ,(20.61645739,"CandyCorn",0.37)
        ,(0.530867073,"CottonCandy",0.37)
        ,(20.54659988,"Twix",0.39)
        ,(20.34254544,"PeppermintPatties",0.39)
        ,(20.29875331,"Twizzlers",0.39)
        ,(20.06333891,"CadburyEggs",0.41)
        ,(20.51611367,"Twix",0.42)
        ,(20.0261656,"CadburyEggs",0.43)
        ,(20.34254544,"CadburyEggs",0.43)
        ,(20.51611367,"CandyCorn",0.45)
        ,(20.36835772,"CottonCandy",0.47)
        ,(0.631359748,"BabyRuth",0.48)
        ,(20.49830931,"Twix",0.50)
        ,(0.741204973,"JuniorMints",0.54)
        ,(0.530867073,"MMs",0.54)
        ,(20.02687584,"CadburyEggs",0.55)
        ,(20.0261656,"TootsieRolls",0.57)
        ,(20.04598065,"CadburyEggs",0.57)
        ,(0.54845489,"MMs",0.59)
        ,(20.03078729,"Twix",0.59)
        ,(0.986711586,"CadburyEggs",0.60)
        ,(0.832297432,"BabyRuth",0.61)
        ,(20.49830931,"CottonCandy",0.62)
        ,(20.03446014,"Twix",0.65)
        ,(20.02687584,"PeppermintPatties",0.65)
        ,(20.34254544,"TootsieRolls",0.67)
        ,(20.12199944,"PeppermintPatties",0.71)
        ,(20.03078729,"PeppermintPatties",0.73)
        ,(20.04712901,"JellyBelly",0.73)
        ,(20.04712901,"HersheyBar",0.73)
        ,(20.54659988,"HersheyBar",0.74)
        ,(20.54659988,"JellyBelly",0.74)
        ,(20.49830931,"PeppermintPatties",0.78)
        ,(20.51611367,"Kit-Kat",0.78)
        ,(20.51611367,"Peeps",0.78)
        ,(20.06333891,"Twix",0.78)
        ,(20.06333891,"TootsieRolls",0.78)
        ,(0.530867073,"SwedishFish",0.85)
        ,(0.530867073,"MilkyWay",0.85)
        ,(20.0824811,"Twizzlers",0.90)
        ,(20.04598065,"PeppermintPatties",0.90)
        ,(20.54659988,"PeppermintPatties",0.91)
        ,(20.54659988,"Kit-Kat",0.96)
        ,(20.0824811,"CottonCandy",0.99)
        ,(20.55374424,"CadburyEggs",1.00)
        ,(20.0261656,"HersheyBar",1.00)
        ,(20.03446014,"PeppermintPatties",1.01)
        ,(0.832297432,"Twizzlers",1.02)
        ,(0.598936468,"Snickers",1.02)
        ,(20.55374424,"CandyCorn",1.02)
        ,(20.34254544,"Twix",1.03)
        ,(0.674523463,"BabyRuth",1.09)
        ,(20.04598065,"Twix",1.10)
        ,(0.530867073,"CadburyEggs",1.10)
        ,(0.631359748,"MMs",1.10)
        ,(0.740648769,"PeppermintPatties",1.11)
        ,(20.04598065,"JellyBelly",1.15)
        ,(20.04598065,"HersheyBar",1.15)
        ,(20.51611367,"PeppermintPatties",1.17)
        ,(0.832297432,"Reeses",1.17)
        ,(20.02687584,"HersheyBar",1.20)
        ,(20.0261656,"Twix",1.20)
        ,(20.02687584,"JellyBelly",1.20)
        ,(20.03078729,"JellyBelly",1.21)
        ,(20.03078729,"HersheyBar",1.21)
        ,(0.832297432,"JuniorMints",1.25)
        ,(0.674523463,"Reeses",1.32)
        ,(0.598936468,"BabyRuth",1.33)
        ,(0.986711586,"JuniorMints",1.35)
        ,(20.06333891,"HersheyBar",1.39)
        ,(20.06333891,"JellyBelly",1.39)
        ,(0.721368367,"BabyRuth",1.42)
        ,(20.34254544,"HersheyBar",1.50)
        ,(20.34254544,"JellyBelly",1.50)
        ,(20.51611367,"JellyBelly",1.52)
        ,(20.51611367,"HersheyBar",1.52)
        ,(0.70609509,"PeppermintPatties",1.54)
        ,(20.49830931,"HersheyBar",1.55)
        ,(20.49830931,"JellyBelly",1.55)
        ,(20.03446014,"JellyBelly",1.56)
        ,(20.03446014,"HersheyBar",1.56)
        ,(0.674523463,"PeppermintPatties",1.58)
        ,(0.437058824,"MMs",1.61)
        ,(0.631359748,"Reeses",1.63)
        ,(0.789668188,"MMs",1.64)
        ,(20.36835772,"TootsieRolls",1.66)
        ,(0.789668188,"Snickers",1.67)
        ,(0.789668188,"Reeses",1.67)
        ,(0.789668188,"CadburyEggs",1.67)
        ,(0.789668188,"PeppermintPatties",1.67)
        ,(0.789668188,"JuniorMints",1.67)
        ,(0.598936468,"CadburyEggs",1.67)
        ,(20.0824811,"CadburyEggs",1.71)
        ,(20.55374424,"Reeses",1.75)
        ,(20.49830931,"CandyCorn",1.81)
        ,(20.49437869,"CottonCandy",1.81)
        ,(20.49437869,"Twizzlers",1.81)
        ,(0.674523463,"CadburyEggs",1.85)
        ,(0.674523463,"JuniorMints",1.85)
        ,(20.49830931,"Kit-Kat",1.93)
        ,(20.51611367,"BabyRuth",1.96)
        ,(20.55374424,"Snickers",2.00)
        ,(0.789668188,"HersheyKiss",2.00)
        ,(20.49437869,"CandyCorn",2.00)
        ,(20.36835772,"CadburyEggs",2.01)
        ,(0.598936468,"JuniorMints",2.08)
        ,(20.56107789,"CandyCorn",2.09)
        ,(20.0824811,"TootsieRolls",2.25)
        ,(0.740648769,"BabyRuth",2.37)
        ,(0.760911235,"Twizzlers",2.49)
        ,(0.70609509,"BabyRuth",2.73)
        ,(0.627161297,"BabyRuth",2.75)
        ,(0.54845489,"Twix",2.77)
        ,(20.02687584,"Twix",2.82)
        ,(20.29875331,"CadburyEggs",2.82)
        ,(20.36835772,"PeppermintPatties",2.86)
        ,(0.674523463,"MMs",2.86)
        ,(20.49830931,"Peeps",2.98)
        ,(0.674523463,"HersheyKiss",3.00)
        ,(0.631359748,"HersheyKiss",3.00)
        ,(0.631359748,"HersheyBar",3.00)
        ,(20.54659988,"Peeps",3.01)
        ,(20.49437869,"PeppermintPatties",3.14)
        ,(0.760911235,"BabyRuth",3.25)
        ,(20.54659988,"BabyRuth",3.26)
        ,(20.0824811,"HersheyBar",3.32)
        ,(20.0824811,"JellyBelly",3.32)
        ,(0.721368367,"Snickers",3.39)
        ,(0.679748517,"BabyRuth",3.43)
        ,(0.627161297,"CandyCorn",3.43)
        ,(20.0824811,"Twix",3.50)
        ,(0.70609509,"MMs",3.55)
        ,(0.740648769,"Snickers",3.63)
        ,(0.530867073,"Twix",3.66)
        ,(20.04712901,"Kit-Kat",3.87)
        ,(20.55374424,"PeppermintPatties",3.91)
        ,(0.70609509,"CadburyEggs",3.92)
        ,(0.740648769,"JuniorMints",3.95)
        ,(20.34254544,"Kit-Kat",3.95)
        ,(0.631359748,"Twix",4.01)
        ,(20.61645739,"CadburyEggs",4.01)
        ,(0.530867073,"HersheyBar",4.03)
        ,(0.741204973,"Twix",4.05)
        ,(0.832297432,"PeppermintPatties",4.14)
        ,(0.721368367,"MMs",4.23)
        ,(20.06333891,"PeppermintPatties",4.23)
        ,(0.631359748,"CadburyEggs",4.38)
        ,(20.36835772,"Twix",4.38)
        ,(0.627161297,"PeppermintPatties",4.40)
        ,(0.721368367,"CadburyEggs",4.43)
        ,(0.437058824,"TootsieRolls",4.44)
        ,(0.598936468,"Twix",4.44)
        ,(0.437058824,"JellyBelly",4.44)
        ,(0.986711586,"JellyBelly",4.48)
        ,(0.674523463,"Twizzlers",4.49)
        ,(20.55374424,"TootsieRolls",4.49)
        ,(20.02687584,"JuniorMints",4.57)
        ,(0.679748517,"Snickers",4.68)
        ,(20.02687584,"BabyRuth",4.70)
        ,(0.679748517,"MMs",4.76)
        ,(20.04712901,"JuniorMints",4.77)
        ,(0.627161297,"Snickers",4.79)
        ,(0.54845489,"JellyBelly",4.88)
        ,(20.29875331,"JuniorMints",4.90)
        ,(0.721368367,"JuniorMints",4.95)
        ,(0.70609509,"Snickers",4.99)
        ,(0.70609509,"Twix",4.99)
        ,(0.832297432,"HersheyKiss",5.00)
        ,(20.29875331,"PeppermintPatties",5.16)
        ,(0.70609509,"JuniorMints",5.23)
        ,(0.832297432,"CadburyEggs",5.23)
        ,(20.49830931,"BabyRuth",5.27)
        ,(20.29875331,"TootsieRolls",5.29)
        ,(0.741204973,"Peeps",5.44)
        ,(0.627161297,"MMs",5.53)
        ,(0.627161297,"CadburyEggs",5.54)
        ,(0.54845489,"PeppermintPatties",5.67)
        ,(20.36835772,"JellyBelly",5.69)
        ,(20.36835772,"HersheyBar",5.69)
        ,(0.598936468,"MMs",5.77)
        ,(0.631359748,"SwedishFish",5.80)
        ,(0.631359748,"MilkyWay",5.80)
        ,(0.741204973,"JellyBelly",5.80)
        ,(0.740648769,"CadburyEggs",5.85)
        ,(0.989637517,"PeppermintPatties",5.93)
        ,(20.34254544,"BabyRuth",5.96)
        ,(0.760911235,"CottonCandy",6.11)
        ,(20.29875331,"BabyRuth",6.15)
        ,(0.679748517,"JuniorMints",6.17)
        ,(20.55374424,"JuniorMints",6.23)
        ,(20.61645739,"Twizzlers",6.26)
        ,(0.760911235,"Snickers",6.36)
        ,(0.760911235,"Twix",6.36)
        ,(0.832297432,"Twix",6.41)
        ,(20.49437869,"TootsieRolls",6.45)
        ,(20.51611367,"JuniorMints",6.46)
        ,(0.679748517,"CadburyEggs",6.47)
        ,(0.760911235,"CadburyEggs",6.48)
        ,(0.816603268,"PeppermintPatties",6.59)
        ,(0.918954156,"PeppermintPatties",6.61)
        ,(20.0261656,"CandyCorn",6.64)
        ,(0.832297432,"SwedishFish",6.64)
        ,(0.832297432,"MilkyWay",6.64)
        ,(20.49437869,"Snickers",6.65)
        ,(20.49437869,"BabyRuth",6.66)
        ,(20.12199944,"Twizzlers",6.76)
        ,(20.12199944,"CottonCandy",6.76)
        ,(0.740648769,"MMs",6.83)
        ,(20.04598065,"JuniorMints",6.84)
        ,(0.986711586,"Twix",6.94)
        ,(20.12199944,"TootsieRolls",6.96)
        ,(20.03446014,"JuniorMints",6.99)
        ,(20.55374424,"HersheyKiss",7.00)
        ,(20.55374424,"MMs",7.01)
        ,(0.712355086,"Twix",7.02)
        ,(20.06333891,"BabyRuth",7.05)
        ,(20.49437869,"Reeses",7.06)
        ,(0.588235294,"JellyBelly",7.08)
        ,(20.12199944,"CadburyEggs",7.11)
        ,(0.674523463,"CottonCandy",7.12)
        ,(0.54845489,"Kit-Kat",7.13)
        ,(20.34254544,"Peeps",7.15)
        ,(20.55374424,"BabyRuth",7.22)
        ,(20.02687584,"Peeps",7.22)
        ,(20.61645739,"CottonCandy",7.30)
        ,(0.712355086,"JuniorMints",7.31)
        ,(0.530867073,"TootsieRolls",7.33)
        ,(20.49830931,"JuniorMints",7.45)
        ,(0.588235294,"TootsieRolls",7.50)
        ,(0.721368367,"Reeses",7.55)
        ,(20.54659988,"JuniorMints",7.61)
        ,(20.12199944,"Twix",7.67)
        ,(20.12199944,"JellyBelly",7.71)
        ,(20.12199944,"HersheyBar",7.71)
        ,(0.679748517,"Twix",7.76)
        ,(0.789668188,"BabyRuth",7.83)
        ,(0.740648769,"Reeses",7.90)
        ,(0.760911235,"MMs",7.92)
        ,(0.631359748,"JellyBelly",8.01)
        ,(0.679748517,"Peeps",8.26)
        ,(0.832297432,"Kit-Kat",8.28)
        ,(0.598936468,"Twizzlers",8.28)
        ,(0.530867073,"JellyBelly",8.30)
        ,(20.49437869,"MMs",8.31)
        ,(0.54845489,"HersheyBar",8.32)
        ,(0.832297432,"CandyCorn",8.33)
        ,(0.789668188,"Kit-Kat",8.33)
        ,(0.789668188,"Twix",8.33)
        ,(0.707955183,"CadburyEggs",8.33)
        ,(0.740648769,"CandyCorn",8.37)
        ,(0.598936468,"Reeses",8.40)
        ,(0.832297432,"CottonCandy",8.52)
        ,(0.986711586,"SwedishFish",8.60)
        ,(0.986711586,"MilkyWay",8.60)
        ,(20.34254544,"JuniorMints",8.66)
        ,(20.29875331,"Reeses",8.72)
        ,(20.12199944,"Kit-Kat",8.74)
        ,(20.0824811,"PeppermintPatties",8.77)
        ,(0.627161297,"JuniorMints",8.82)
        ,(0.989637517,"JuniorMints",8.83)
        ,(20.02687584,"Reeses",8.84)
        ,(20.49437869,"JuniorMints",8.87)
        ,(0.789668188,"SwedishFish",8.89)
        ,(0.789668188,"MilkyWay",8.89)
        ,(20.49437869,"Twix",9.27)
        ,(0.70609509,"Reeses",9.38)
        ,(0.631359748,"Twizzlers",9.39)
        ,(0.588235294,"CandyCorn",9.39)
        ,(20.0261656,"JuniorMints",9.40)
        ,(20.29875331,"Snickers",9.60)
        ,(0.740648769,"Twix",9.79)
        ,(20.51611367,"Reeses",9.81)
        ,(0.760911235,"Reeses",9.85)
        ,(0.588235294,"Peeps",10.00)
        ,(0.679748517,"PeppermintPatties",10.00)]


def find_best_fit(feature_values, feature_names):
    algorithm = []
    for idx, v in enumerate(feature_values):
        if feature_names[idx].lower() == 'green':
            for m in model:
                try:
                    algorithm.append(((abs(m[0] - float(v)) ** 2) * (1 + (m[2] / 100)), m[1]))
                except:
                    break
    algorithm.sort()
    sequence = ''
    for idx, t in enumerate(algorithm[0:3]):
        sequence += t[1]
        if idx != 2:
            sequence += ','
    return sequence


if __name__ == '__main__':
    if len(sys.argv) >= 3:
        program_name, in_file_name, out_file_name = sys.argv[0:3]
        with open(in_file_name, 'rU') as in_file:
            features = None
            with open(out_file_name, 'w') as out_file:
                for lidx, line in enumerate(in_file):
                    if lidx == 0:
                        features = line.split(',')
                    else:
                        feature_vector = line.split(',')
                        out_file.write(find_best_fit(feature_vector, features) + '\n')
    else:
        print 'Program requires 2 arguments: <input_file>, <output_file>'
        os._exit(1)
